package com.zl.easybuy.service.impl;

import com.zl.easybuy.bo.BaseBo;
import com.zl.easybuy.bo.NewsBo;
import com.zl.easybuy.mapper.NewsMapper;
import com.zl.easybuy.mapper.UserMapper;
import com.zl.easybuy.pojo.News;
import com.zl.easybuy.service.NewsService;
import com.zl.easybuy.util.Pages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class NewsServiceImpl implements NewsService {
    @Autowired
    NewsMapper newsMapper;
    @Override
    public List<News> findNewsOf(int i) {
        List<News> newsList=new ArrayList<>();
        NewsBo newsBo=new NewsBo();
        News news=new News();
        newsBo.setNews(news);
        newsBo.setPage(true);
        newsBo.setPageNo(1);
        newsBo.setPageSize(i);
        newsBo.setPage(true);
        newsBo.setStatus(2);
        newsBo.setStatusField("createTime");
        newsList=newsMapper.findNews(newsBo);
        return newsList;
    }

    @Override
    public Pages<News> findNewsBy(Integer pageNo) {
        Pages<News> pages=new Pages<>();
        NewsBo newsBo=new NewsBo();
        newsBo.setPage(true);
        newsBo.setPageSize(5);
        newsBo.setPageNo(pageNo);
        newsBo.setStatus(2);
        newsBo.setStatusField("createtime");
        pages.setRecord(newsMapper.findNews(newsBo));
        pages.setPageSize(5);
        pages.setPageNo(pageNo);
        pages.setTotalCount(newsMapper.count());
        pages.setUrl("admin/news/queryNewsList?i=1");
        return pages;
    }

    @Override
    public News findNewById(Integer id) {
        if(id==null){
            return null;
        }
        return newsMapper.findNewById(id);
    }
}
